package com.cn.wanxi.servlet;

import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.service.ICompanyService;
import com.cn.wanxi.service.INavService;
import com.cn.wanxi.service.impl.CompanyServiceImpl;
import com.cn.wanxi.service.impl.NavServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/home")
public class HomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        /**
         * 第二阶段：
         * 1.调用服务逻辑层
         * 2.取得数据
         * 3.将数据保存在request里面
         * 4.返回页面
         */
//        CompanyService companyService = new CompanyService();
        ICompanyService iCompanyService=new CompanyServiceImpl();
        CompanyModel companyModel = iCompanyService.getCompanyModel();
        req.setAttribute("companyModel", companyModel);//key  value
//导航信息

//        NavService navService = new NavService();
        INavService iNavService=new NavServiceImpl();
        //创建一个集合，集合的类型为NavModel
        List<NavModel> navModelList = iNavService.getNavModelList();

        req.setAttribute("navModelList", navModelList);//key  value
//新闻信息
//        NewsService newsService = new NewsService();
//        List<NewsModel> newsModelList = newsService.getNewsModelList();
//        req.setAttribute("newsModelList", newsModelList);//key  value
        req.getRequestDispatcher("/jsp/home.jsp").forward(req, resp);
    }
}
